package org.enwey.icarenew.Adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import org.enwey.icarenew.Component.NewStyleItem;
import org.enwey.icarenew.Model.NewStyle;

import java.util.List;

/**
 * Created by enwey on 2014/11/20.
 */
public class MenuStyleAdapter extends BaseAdapter {
    private List<NewStyle> mNewStyleList;
    private Context context;

    public MenuStyleAdapter(Context context) {
        this.context = context;
    }
    public void setMenuStyleList(List<NewStyle> list) {
        this.mNewStyleList = list;
    }
    @Override
    public int getCount() {
        return (mNewStyleList != null ? mNewStyleList.size() : 0);
    }

    @Override
    public Object getItem(int position) {
        return (mNewStyleList != null ? mNewStyleList.get(position) : null);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        NewStyleItem styleItem = null;
        if (convertView == null) {
            styleItem = new NewStyleItem(context);
        }else {
            styleItem = (NewStyleItem) convertView;
        }

        styleItem.setStyleData(mNewStyleList.get(position));

        return styleItem;
    }
}
